#ifndef NIXONBOT_CORE_BNCS_PROTOCOL_AUTHINFOCLIENT_H_
#define NIXONBOT_CORE_BNCS_PROTOCOL_AUTHINFOCLIENT_H_

#include <nixonbot/core/bncs/protocol/Message.h>
#include <nixonbot/core/bncs/protocol/MessageFactory.h>

namespace nixonbot {
namespace core {
namespace bncs {
namespace protocol {

struct AuthInfoClientData : public QSharedData
{
	quint32 protocolId;
	quint32 platformId;
	quint32 productId;
	quint32 version;
	quint32 language;
	quint32 localIP;
	quint32 tzbias;
	quint32 localeId;
	quint32 langId;
	QByteArray countryAbbr;
	QByteArray countryFull;
};

class AuthInfoClient : public Message
{
public:
	static const int id = 0x50;
	BNCS_MESSAGE_CLIENT_REGISTER(AuthInfoClient, id);

public:
	QSharedDataPointer<AuthInfoClientData> d;

public:
	AuthInfoClient()
	{
		d = new AuthInfoClientData();
	}
	
	virtual AuthInfoClient* create()
	{
		return new AuthInfoClient();
	}
	
	virtual quint32 id()
	{
		return id;
	}

	virtual int size()
	{
		return sizeof(d->protocolId) + sizeof(d->platformId) + sizeof(d->productId) +
		       sizeof(d->version) + sizeof(d->language) + sizeof(d->localIP) +
		       sizeof(d->tzbias) + sizeof(d->localeId) + sizeof(d->langId) +
		       (d->countryAbbr.size() + 1) + (d->countryFull.size() + 1);
	}

protected:
	virtual void readFrom(QDataStream& ds)
	{
		int bo = ds.byteOrder();
		ds.setByteOrder(QDataStream::LittleEndian);

		ds >> d->protocolId;
		ds >> d->platformId;
		ds >> d->productId;
		ds >> d->version;
		ds >> d->language;
		ds >> d->localIP;
		ds >> d->tzbias;
		ds >> d->localeId;
		ds >> d->langId;
		d->countryAbbr = readStringFrom(ds);
		d->countryFull = readStringFrom(ds);

		ds.setByteOrder((QDataStream::ByteOrder)bo);
	}

	virtual void writeTo(QDataStream& ds)
	{
		int bo = ds.byteOrder();
		ds.setByteOrder(QDataStream::LittleEndian);

		ds << d->protocolId;
		ds << d->platformId;
		ds << d->productId;
		ds << d->version;
		ds << d->language;
		ds << d->localIP;
		ds << d->tzbias;
		ds << d->localeId;
		ds << d->langId;
		writeStringTo(ds, d->countryAbbr);
		writeStringTo(ds, d->countryFull);
		
		ds.setByteOrder((QDataStream::ByteOrder)bo);
	}
};

}
}
}
}

#endif /* NIXONBOT_CORE_BNCS_PROTOCOL_AUTHINFOCLIENT_H_ */
